/**
 * @description 自动import导入所有 vuex 模块
 */

import {
	createStore
} from 'vuex';
import createPersistedState from "vuex-persistedstate";
import SecureLS from "secure-ls";
var ls = new SecureLS({
	isCompression: false
});
import stringify from 'fast-safe-stringify'


// const files = require.context('./modules', false, /\.js$/);
const modules = {}
// files.keys().forEach((key) => {
//  modules[key.replace(/(\.\/|\.js)/g, '')] = files(key).default
// })


// const metas = import.meta.globEager('./modules/*.js')

const metas = import.meta.glob('./modules/*.js', {
	import: 'default',
	eager: true
})

for (let key in metas) {
	let k = key.replace('modules/', '')
	modules[k.replace(/(\.\/|\.js)/g, '')] = metas[key]
}

export default createStore({
	modules: modules,
	plugins: [createPersistedState({
		paths: ["cache2"],
		storage: {
			getItem: (key) => {
				return ls.get(key)
			},
			setItem: (key, value) => {
				ls.set(key, value)
			},
			removeItem: (key) => ls.remove(key),
		},
	})]
});
